//-------
// cookie
//----
jQuery.extend({
	//获取cookie
    //$.getCookie(name)
    getCookie: function (name) {
        if ( document.cookie.length>0 ){
          	var c_start=document.cookie.indexOf(name + "=");
          	var c_end=document.cookie.indexOf(";",c_start);
         	if (c_start!=-1){ 
            	c_start=c_start + name.length+1 
           		if (c_end==-1) c_end=document.cookie.length
            	return unescape(document.cookie.substring(c_start,c_end))
            } 
        }
        return "";
    },
    //设置cookie
    //$.setCookie(objName, objValue)
    setCookie:function(objName, objValue, objHours){
        var str = objName + "=" + escape(objValue); 
        var objHours =objHours  ||   Infinity;
        if (objHours > 0) {//为0时不设定过期时间，浏览器关闭时cookie自动消失 
	        var date = new Date(); 
	        var ms = objHours * 3600 * 1000; 
	        date.setTime(date.getTime() + ms); 
	        str += "; expires=" + date.toGMTString(); 
        } 
        if(objHours===Infinity){
            str += "; expires=Fri, 31 Dec 9999 23:59:59 GMT";
        }
        document.cookie = str+";path=/"; 
    }
});

